package club.mrxiao.gps.socket.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * 日期工具
 * @author xiaoyu
 */
public class DateUtil {

    /**
     * 日期格式字符串转换成时间戳
     *
     * @param dateStr 字符串日期
     * @param format   如：yyyy-MM-dd HH:mm:ss
     *d
     * @return
     */
    public static String date2TimeStamp(String dateStr, String format) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            return String.valueOf(sdf.parse(dateStr).getTime() / 1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public static int[] calendarToCurrentTimeList(){
        Calendar ca = Calendar.getInstance();

        int year = ca.get(Calendar.YEAR) - 2000; //用1个字节标识年份
        int month = ca.get(Calendar.MONTH) + 1; //第一个月从0开始，所以得到月份＋1
        int day = ca.get(Calendar.DAY_OF_MONTH);
        int hour = ca.get(Calendar.HOUR_OF_DAY);
        int minute = ca.get(Calendar.MINUTE);
        int second = ca.get(Calendar.SECOND);
        return new int[]{year,month,day,hour,minute,second};
    }
}
